package com.lpf.熔断器;

public class Main {
	public static void main(String[] args) {
		Context context = new Context();
		context.state = new CloseState();

		context.switchState();
		context.switchState();
		context.switchState();
		context.switchState();
		context.switchState();
	}
}

/**
 * 状态上下文
 */
class Context {
	public State state;

	void switchState() {
		state.switchState(this);
	}
}

/**
 * 状态的抽象
 */
interface State {
	void switchState(Context context);
}

/**
 * 开状态
 **/
class OpenState implements State {

	public void switchState(Context context) {
		System.out.println("当前状态：开");
		context.state = new CloseState();
	}
}

/**
 * 关状态
 **/
class CloseState implements State {

	public void switchState(Context context) {
		System.out.println("当前状态：关");
		context.state = new OpenState();
	}
}